﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Ccr.Core;
//using Microsoft.Practices.Unity;
using NUnit.Framework;
using XcoAppSpaces.Core;

namespace test.XcoAppSpaces.Core.Error_Reproductions
{
    #region workflow
    class PServerWorker : Port<int>{}

    class ServerWorker : PServerWorker
    {
        public AutoResetEvent Processed = new AutoResetEvent(false);

        [XcoConcurrent]
        void ProcessInt(int a)
        {
            Console.WriteLine("server worker received: {0}", a);
            this.Processed.Set();
        }
    }
    #endregion


    [TestFixture]
    public class testDerivedPortWhenRemoted
    {
        [Test]
        public void Remoted_port_of_derived_type_does_not_throw_an_ex_when_used_in_server()
        {
			using (XcoAppSpace server = new XcoAppSpace("tcp.port=9020"))
            {
                ServerWorker worker = (ServerWorker)server.RunWorker<PServerWorker, ServerWorker>("serverworker");

				using (XcoAppSpace client = new XcoAppSpace("tcp.port=0"))
                {
                    PServerWorker serverworker = client.ConnectWorker<PServerWorker>("localhost:9020/serverworker");
                    serverworker.Post(99);

                    Assert.IsTrue(worker.Processed.WaitOne(1000));
                }
            }
        }
    }
}
